/*
设置
读取 config\config.ini 文件的配置信息
便于用户自定义服务端相关设置和统一管理
*/

package utils

import (
    "fmt"

    "gopkg.in/ini.v1"
)

var (
    AppMode  string
    HttpPort string
    JwtKey   string

    DbHost     string
    DbPort     string
    DbUser     string
    DbPassWord string
    DbName     string

    Storage         string
    Region          string
    EndPonit        string
    AccessKey       string
    SecretKey       string
    BucketName      string
    UseSSL          bool
    LocalUploadPath string

    Model  string
    ApiKey string
)

// 初始化
func init() {
    file, err := ini.Load("config/config.ini")
    if err != nil {
        fmt.Println("配置文件读取错误，请检查文件路径:", err)
    }
    LoadServer(file)
    LoadData(file)
    LoadS3(file)
    LoadAI(file)
}

func LoadServer(file *ini.File) {
    AppMode = file.Section("server").Key("AppMode").MustString("debug")
    HttpPort = file.Section("server").Key("HttpPort").MustString(":3000")
    JwtKey = file.Section("server").Key("JwtKey").MustString("89js82js72")
}

func LoadData(file *ini.File) {
    DbHost = file.Section("database").Key("DbHost").MustString("localhost")
    DbPort = file.Section("database").Key("DbPort").MustString("3306")
    DbUser = file.Section("database").Key("DbUser").MustString("ginblog")
    DbPassWord = file.Section("database").Key("DbPassWord").String()
    DbName = file.Section("database").Key("DbName").MustString("ginblog")
}

func LoadS3(file *ini.File) {
    Storage = file.Section("s3").Key("Storage").MustString("local")
    Region = file.Section("s3").Key("Region").String()
    EndPonit = file.Section("s3").Key("EndPonit").String()
    AccessKey = file.Section("s3").Key("AccessKey").String()
    SecretKey = file.Section("s3").Key("SecretKey").String()
    UseSSL = file.Section("s3").Key("UseSSL").MustBool(true)
    BucketName = file.Section("s3").Key("BucketName").String()
    LocalUploadPath = file.Section("s3").Key("LocalUploadPath").MustString("./upload")
}

func LoadAI(file *ini.File) {
    Model = file.Section("ai").Key("Model").String()
    ApiKey = file.Section("ai").Key("ApiKey").String()
}
